package com.example.boot1.conttoller;

import com.example.boot1.bean.BackDataBean;
import com.example.boot1.bean.VueTable;
import com.example.boot1.service.VueTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class VueTableController {

    @Autowired
    private VueTableService vueTableService;

    /**
     * 查询全部餐桌
     * @return
     */
    @GetMapping("/vue/getTable")
    @ResponseBody
    public ResponseEntity<BackDataBean> getTable(HttpServletRequest request){

        List<VueTable> vtList = vueTableService.getTable();

        ResponseEntity responseEntity = null;
        BackDataBean backDataBean = null;
        if (null!=vtList){
            backDataBean = new BackDataBean();
            backDataBean.setCode(200);
            backDataBean.setMsg("查询成功！");
            backDataBean.setResult(vtList);
            responseEntity = ResponseEntity.status(HttpStatus.OK).body(backDataBean);
        }else {
            backDataBean.setCode(202);
            backDataBean.setMsg("服务器错误！");
            backDataBean.setResult(null);
            responseEntity = ResponseEntity.status(HttpStatus.OK).body(backDataBean);
        }

        return responseEntity;
    }
}
